<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>非受控组件</title>
</head>
<body>
    <div id="root"> </div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>

    <script type="text/babel">
        class App extends React.Component{
            render(){
                return <div>
                        <h2>登录</h2>
                        <form action="">
                            用户名: <input ref={el => this.username = el} type="text" /><br />    
                            密码: <input ref={el => this.password = el} type="password" /><br />    
                            <input type="submit" value="登录" onClick={this.login} />
                        </form>
                    </div>
            }

            login = (e) => {
                //阻止默认行为 建议将阻止默认行为的代码, 放到回调的最上方
                e.preventDefault();

                //获取表单项的值
                let user = this.username.value;
                let pass = this.password.value;

                console.log(`当前用户名为: ${user}  当前密码为: ${pass}`);
            }
        }

        ReactDOM.render(<App />, document.querySelector("#root"));
    </script>
</body>
</html>